#pragma once
#ifdef _WINDOWS // 64位系统没有预定义 WIN32
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C" __declspec(dllexport)
#else
#define DLL_EXPORT_DECL __declspec(dllexport)
#endif
#else
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C"
#else
#define DLL_EXPORT_DECL extern
#endif
#endif

#ifdef _WINDOWS
#define WIN32_LEAN_AND_MEAN //  从 Windows 头文件中排除极少使用的信息
#include "stddef.h"
#define WINAPI __stdcall
#include "../SOPTv3.6.2_20210915/ThostFtdcMdApi.h"
#pragma comment(lib, "../SOPTv3.6.2_20210915/soptthostmduserapi_se.lib")
#else
#define WINAPI
#include "../../SOPTv3.6.2_20210915/ThostFtdcMdApi.h"
#endif

class Quote : ctp_sopt::CThostFtdcMdSpi
{
public:
	// typedef
	typedef int(WINAPI *OnFrontConnectedType)();

	typedef int(WINAPI *OnFrontDisconnectedType)(int nReason);

	typedef int(WINAPI *OnHeartBeatWarningType)(int nTimeLapse);

	typedef int(WINAPI *OnRspUserLoginType)(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspUserLogoutType)(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspErrorType)(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspSubMarketDataType)(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspUnSubMarketDataType)(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspSubForQuoteRspType)(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRspUnSubForQuoteRspType)(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	typedef int(WINAPI *OnRtnDepthMarketDataType)(CThostFtdcDepthMarketDataField *pDepthMarketData);

	typedef int(WINAPI *OnRtnForQuoteRspType)(CThostFtdcForQuoteRspField *pForQuoteRsp);

	// vars
	void *_OnFrontConnected;

	void *_OnFrontDisconnected;

	void *_OnHeartBeatWarning;

	void *_OnRspUserLogin;

	void *_OnRspUserLogout;

	void *_OnRspError;

	void *_OnRspSubMarketData;

	void *_OnRspUnSubMarketData;

	void *_OnRspSubForQuoteRsp;

	void *_OnRspUnSubForQuoteRsp;

	void *_OnRtnDepthMarketData;

	void *_OnRtnForQuoteRsp;

	// funcs
	virtual void OnFrontConnected()
	{
		if (_OnFrontConnected)
		{

			((OnFrontConnectedType)_OnFrontConnected)();
		}
	}
	virtual void OnFrontDisconnected(int nReason)
	{
		if (_OnFrontDisconnected)
		{

			((OnFrontDisconnectedType)_OnFrontDisconnected)(nReason);
		}
	}
	virtual void OnHeartBeatWarning(int nTimeLapse)
	{
		if (_OnHeartBeatWarning)
		{

			((OnHeartBeatWarningType)_OnHeartBeatWarning)(nTimeLapse);
		}
	}
	virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspUserLogin)
		{

			((OnRspUserLoginType)_OnRspUserLogin)(pRspUserLogin, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspUserLogout)
		{

			((OnRspUserLogoutType)_OnRspUserLogout)(pUserLogout, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspError)
		{

			((OnRspErrorType)_OnRspError)(pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspSubMarketData)
		{

			((OnRspSubMarketDataType)_OnRspSubMarketData)(pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspUnSubMarketData)
		{

			((OnRspUnSubMarketDataType)_OnRspUnSubMarketData)(pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspSubForQuoteRsp)
		{

			((OnRspSubForQuoteRspType)_OnRspSubForQuoteRsp)(pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
	{
		if (_OnRspUnSubForQuoteRsp)
		{

			((OnRspUnSubForQuoteRspType)_OnRspUnSubForQuoteRsp)(pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
		}
	}
	virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData)
	{
		if (_OnRtnDepthMarketData)
		{

			((OnRtnDepthMarketDataType)_OnRtnDepthMarketData)(pDepthMarketData);
		}
	}
	virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp)
	{
		if (_OnRtnForQuoteRsp)
		{

			((OnRtnForQuoteRspType)_OnRtnForQuoteRsp)(pForQuoteRsp);
		}
	}
};
